#include "OCMain/zip/BZip2.h"
#include "OCMain/StringUtil.h"
#include <emscripten.h>

using namespace OCPP;

class bz2decompress
{
public:
    static emscripten::val decompress(const emscripten::val &jsUint8Array)
    {
        size_t size = jsUint8Array["length"].as<size_t>();
        std::vector<uint8_t> content;
        content.resize(size);
        emscripten::val view(emscripten::typed_memory_view(
            size,
            content.data()));
        view.call<void>("set", jsUint8Array);

        String dest;
        BZip2::decpressBZ2(content, dest);

        return emscripten::val::global("Uint8Array").new_(emscripten::typed_memory_view(dest.size(), dest.data()));
    }
};